﻿<Window x:Class="View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:view="clr-namespace:View"
        xmlns:viewModel="clr-namespace:ViewModel;assembly=ViewModel"
        xmlns:services="clr-namespace:ViewModel.Services;assembly=ViewModel"
        xmlns:converters="clr-namespace:ValueConverters;assembly=ValueConverters"
        mc:Ignorable="d"
        Title="Notes" Height="450" Width="800" MinHeight="450" MinWidth="800">
    <Window.Resources>
        <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" IsInverted="False"/>
        <DataTemplate x:Key="noteTemplate">
            <StackPanel Margin="3" Orientation="Horizontal" HorizontalAlignment="Right">
                <TextBlock Text="{Binding Title}"
                           Validation.ErrorTemplate="{x:Null}"
                           FontSize="12" Width="auto"
                           TextWrapping="Wrap"/>
                <Ellipse Width="5" Height="5" Fill="#FF9BBAC7" Margin="3"
                         Visibility="{Binding IsEdit, 
                    Converter={StaticResource BoolToVisibilityConverter}, 
                    UpdateSourceTrigger=PropertyChanged}"/>
            </StackPanel>
        </DataTemplate>
    </Window.Resources>
    <Window.DataContext>
        <viewModel:MainViewModel/>
    </Window.DataContext>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="175" 
                              MinWidth="175" 
                              MaxWidth="300"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0" 
              Background="LightGray">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0" Margin="3" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0"
                           Text="Find:"
                           Margin="3"
                           HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <TextBox Grid.Column="1"
                         Background="LightGray"
                         Margin="0, 3, 3, 3"
                         Text="{Binding SearchNoteTitle, UpdateSourceTrigger=PropertyChanged, 
                    Mode=TwoWay}" 
                         VerticalAlignment="Center"/>
            </Grid>
            <Grid Grid.Row="1"
                  Margin="3">
                <ListBox Margin="3"
                         Background="LightGray"
                         BorderThickness="0"
                         ItemsSource="{Binding Notes, 
                            UpdateSourceTrigger=PropertyChanged}"
                         SelectedItem="{Binding SelectedNote, 
                    UpdateSourceTrigger=PropertyChanged}"
                         ItemTemplate="{StaticResource noteTemplate}"/>
            </Grid>
            <Grid Grid.Row="2"
                  Margin="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Button Grid.Column="0"
                        Height="25"
                        Width="auto"
                        Margin="3"
                        Content="Add"
                        Command="{Binding AddNoteCommand}"/>
                <Button Grid.Column="1"
                        Height="25"
                        Width="auto"
                        Margin="0, 3, 3, 3"
                        Content="Delete"
                        Command="{Binding DeleteNoteCommand}"/>
            </Grid>
        </Grid>
        <Grid Grid.Column="1"  
              Margin="50,3,50,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <TextBox FontSize="50"
                         BorderThickness="0"
                         Text="{Binding SelectedNote.Title, UpdateSourceTrigger=PropertyChanged}"
                         IsEnabled="{Binding IsEnabled}">
                    <TextBox.ContextMenu>
                        <ContextMenu Visibility="{Binding IsEdit, 
                            Converter={StaticResource BoolToVisibilityConverter}, UpdateSourceTrigger=PropertyChanged}">
                            <MenuItem Header="Save" Command="{Binding SaveNoteCommand}"/>
                        </ContextMenu>
                    </TextBox.ContextMenu>
                </TextBox>
            </Grid>
            <Grid Grid.Row="1"
                    Margin="0, 10, 0, 0">
                <RichTextBox 
                         VerticalScrollBarVisibility="Auto"
                         BorderThickness="0"
                         IsEnabled="{Binding IsEnabled}"
                         AcceptsReturn="True"
                         AcceptsTab="True"
                         SpellCheck.IsEnabled="True"
                         services:RichTextBoxHelper.DocumentXaml="{Binding SelectedNote.Text, 
                    UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
                    <FlowDocument>
                    </FlowDocument>
                    <RichTextBox.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Save" Command="{Binding SaveNoteCommand}"/>
                        </ContextMenu>
                    </RichTextBox.ContextMenu>
                </RichTextBox>
            </Grid>
        </Grid>
        <GridSplitter Grid.Column="0" Width="2" Background="White"/>
    </Grid>
</Window>
